"""
Pydantic 数据模式定义
"""

from datetime import datetime
from typing import Optional
from uuid import UUID
from pydantic import BaseModel, EmailStr, Field


# ============== 用户相关 ==============
class UserCreate(BaseModel):
    """用户注册模式"""

    username: str = Field(..., min_length=3, max_length=50)
    email: EmailStr
    password: str = Field(..., min_length=6)


class UserResponse(BaseModel):
    """用户响应模式"""

    user_id: UUID
    username: str
    email: str
    created_at: datetime

    class Config:
        from_attributes = True


class Token(BaseModel):
    """JWT Token 响应"""

    access_token: str
    token_type: str = "bearer"


class TokenData(BaseModel):
    """Token 数据"""

    user_id: Optional[UUID] = None
    username: Optional[str] = None


# ============== 岗位相关 ==============
class PositionCreate(BaseModel):
    """创建岗位模式"""

    title: str = Field(..., max_length=100)
    jd_text: str


class PositionResponse(BaseModel):
    """岗位响应模式"""

    position_id: UUID
    title: str
    jd_text: str
    white_paper_tag: str
    created_at: datetime

    class Config:
        from_attributes = True


# ============== 面试会话相关 ==============
class InterviewSessionCreate(BaseModel):
    """创建面试会话模式（支持直接传递简历文本）"""

    position_id: UUID
    cv_text: Optional[str] = None  # 现在支持文件上传，cv_text 变为可选


class InterviewSessionResponse(BaseModel):
    """面试会话响应模式"""

    session_id: UUID
    user_id: UUID
    position_id: UUID
    is_ended: bool
    created_at: datetime
    initial_message: Optional[str] = None  # 初始问候消息（仅在创建时返回）

    class Config:
        from_attributes = True


# ============== 聊天相关 ==============
class ChatRequest(BaseModel):
    """聊天请求模式"""

    session_id: UUID
    message: str


class MessageResponse(BaseModel):
    """消息响应模式"""

    message_id: UUID
    role: str
    content: str
    timestamp: datetime

    class Config:
        from_attributes = True


# ============== 分析报告相关 ==============
class AnalyzeRequest(BaseModel):
    """分析请求模式"""

    session_id: UUID
